package com.elcl.support;

import java.lang.reflect.Field;

import com.elcl.storage.ApplicationCache;

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;

/**
 * @author lichunlin 状态栏中的控制
 */
public class StatusBarUtils {

	/**
	 * 沉浸式体验（4.4以后，修改状态栏）
	 */
	public static void setActFullScreen(Activity activity, View root) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			// 透明状态栏
			activity.getWindow().addFlags(
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			// activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			if (null != root) {
				root.setPadding(0, getStatusBarHeight(), 0, 0);
			}
		}
	}

	/**
	 * 获取状态栏高度
	 * 
	 * @return
	 */
	public static int getStatusBarHeight() {
		int sbar = 0;
		if (sbar > 0) {
			return sbar;
		}
		Class<?> c = null;
		Object obj = null;
		Field field = null;
		int x = 0;
		try {
			c = Class.forName("com.android.internal.R$dimen");
			obj = c.newInstance();
			field = c.getField("status_bar_height");
			x = Integer.parseInt(field.get(obj).toString());
			sbar = ApplicationCache.context.getResources()
					.getDimensionPixelSize(x);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return sbar;
	}

}
